<?php
require_once '../classes/includeAll.php';
require '../resources/getConnection.php';
$roomAndLevelClass = new roomAndLevel($connection);
$allLevel = $roomAndLevelClass->getAllLevel();
$allRoomByLevel = array();
foreach ($allLevel as $level) {
  array_push($allRoomByLevel,array($level,$roomAndLevelClass->getAllRoomsPerLevel($level["ID"])));
}

$connection->disconnectDB();
$head='<link rel="stylesheet" type="text/css" href="../design/css/rooms.css">'
      .'<script src="../javascript/pagesJavascript/rooms.js" type="text/javascript"></script>';
$title = "R&auml;me und Stockwerke";
require '../menu/head.php';

?>
<h1>R&auml;ume und Stockwerke</h1>
<div id="tableDiv">
<form id="roomLevelForm">
  <table id="roomLevelTable">
    <thead>
      <tr>
        <th>Stockwerk</th>
        <th>Raum Nr.</th>
        <th>Raum</th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <?php
      $i=0;
      foreach ($allRoomByLevel as $info) {
        echo '<tr class="level">'
            . '<td name="entry['.$info[0]["ID"].'][0]" info="levelName">'.$info[0]["name"].'</td>'
            . '<td></td>'
            . '<td></td>'
            . '<td objid="'.$info[0]["ID"].'"><img src="../design/pictures/delete.png" width="20" alt="X"/></td>'
           . '</tr>';
        $i++;
        if($i%2)
        {
          echo '<tr class="padding" style="display: none;"></tr>';
          $i=0;
        }
           foreach ($info[1] as $room) {         
            echo '<tr class="room">'
                . '<td name="entry['.$room["ID"].'][1]" info="level"></td>'
                . '<td name="entry['.$room["ID"].'][2]" info="roomNumber">'.$room["number"].'</td>'
                . '<td name="entry['.$room["ID"].'][3]" info="roomName">'.$room["name"].'</td>'
                . '<td objid="'.$room["ID"].'"><img src="../design/pictures/delete.png" width="20" alt="X"/></td>'
               . '</tr>';
            $i++;
           }
      }
      ?>
    </tbody>
  </table>
</form>
  <div id="submitArea"></div>
</div>

<div id="addDiv">
  <div id="addRoom">
    <h2>Raum hinzuf&uuml;gen</h2>
    <form id="newRoom">
      <table class="newTable" id="newRoomTable">
        <tbody>
          <tr><td><input type="text" name="roomnumber" value="" placeholder="Raum Nummer" class="newInput"/></td><td></td></tr>
          <tr><td><input type="text" name="roomname" value="" placeholder="Raum Bezeichnung" class="newInput"/></td><td></td></tr>
          <tr><td>
            <select name="levelselect" id="levelSelect">
            <option value="-1" disabled selected style="display:none;">Stockwerk w&auml;hlen</option>
            <?php  
            foreach ($allLevel as $level) {              
              echo'<option value="'.$level["ID"].'">'.$level["name"].'</option>';
            }  
            ?>
            </select>
            </td><td></td></tr>
          <tr><td><input type="button" value="&Uuml;bernehmen" name="addSupplier" id="btnNewRoom" /></td><td></td></tr>
        </tbody>
      </table>
    </form>
  </div>
  <div id="addLevel">
    <h2>Stockwerk hinzuf&uuml;gen</h2>
    <form id="newLevel">
      <table class="newTable" id="newLevelTable">
        <tbody>
          <tr><td><input type="text" name="levelname" value="" placeholder="Stockwerkname" class="newInput"/></td><td></td></tr>
          <tr><td><input type="button" value="&Uuml;bernehmen" name="addSupplier" id="btnNewLevel" /></td><td></td></tr>
        </tbody>
      </table>
    </form>
  </div>
</div>
<?php
require '../menu/footer.php';